package com.devsoft.foodfrenzy;

import java.util.ArrayList;
import org.andengine.entity.sprite.TiledSprite;

import com.badlogic.gdx.physics.box2d.Body;

public class Food {
	
	private String name;
	private int pos_x;
	private int pos_y;
	private int cooked = 0;			//food drops uncooked, the more its flipped, the more cooked
	private int cookedMax = 3;		//after 3 hits, the food is fully cooked
	private int foodindex = 0;
	private double weight;			//each food has unique weight, reps approx lbs
	private boolean bounce = false;	//when false, food is falling 
	private boolean fullyCooked = false;
	private TiledSprite sprite;
	private Body body;
	public static ArrayList <Food> foodList = new ArrayList <Food> ();
	
	public Food(){}
	
	public Food(String name, double weight, TiledSprite image)
	{
		this.name = name;
		this.weight = weight;
		this.sprite = image;
		sprite.setCurrentTileIndex(0);
	}
	
	
	public String getName()
	{
		return name;
	}
	
	public TiledSprite getSprite()
	{
		return sprite;
		
	}
	
	
	public void setBody(Body body)
	{
		this.body = body;
		
	}
	
	
	public Body getBody()
	{
		return body;
		
	}
	
	
	public int getPositionX()
	{
		return pos_x;
		
	}
	
	
	public int getPositionY()
	{
		return pos_y;
		
	}
	
	
	public void setPositionX(int pos)
	{
		this.pos_x = pos;
		
	}
	
	
	public void setPositionY(int pos)
	{
		this.pos_y = pos;
		
	}
	
	public void incrementCooked(boolean inst)
	{
		if(inst == false)
		{
			this.cooked++;
			UserData.getInstance().increaseUnlockVal(4);
		}
		else
		{
			this.cooked = this.cookedMax;
		}
		
		if (this.cooked == this.cookedMax)
		{
			fullyCooked = true;
			UserData.getInstance().increaseUnlockVal(5);
		}
		else{
			this.sprite.setCurrentTileIndex(this.cooked);
		}
		
	}
	
	public void changeSprite(int index){
		this.sprite.setCurrentTileIndex(index);
	}
	
	public double getWeight()
	{
		return weight;
		
	}
	
	
	public int getCooked()
	{
		return cooked;
		
	}
	
	
	public int getCookedMax()
	{
		return cookedMax;
		
	}
	
	
	public boolean getBounce()
	{
		return bounce;
		
	}
	
	public void setBounce(boolean state)
	{
		this.bounce = state;
		
	}
	
	
	public boolean getFullyCooked()
	{
		return fullyCooked;
		
	}
	
	
	public static void createFood(Food food)
	{
		foodList.add(food);
	}
	
	public static ArrayList <Food> getFoodList()
	{
		return foodList;
		
	}
	
	
	public ArrayList <Food> removeFood(ArrayList <Food> currentFood, Food foodCooked)	//removes food fully cooked on screen
	{
		currentFood.remove(foodCooked);
		
		//add points to player score
		
		return currentFood;
		
	}
	
	public int getFoodIndex(String name)
	{
		for(int i = 0; i < 18; i++)
		{
			if(name == foodList.get(i).getName())
			{
				foodindex = i;
			}
		}
		return foodindex;
	}
	
}
